//
//  TKIMAccountStyle1TableViewCell.m
//  test2
//
//  Created by TryHone on 17/1/16.
//  Copyright © 2017年 TryHone. All rights reserved.
//

#import "TKIMAccountStyle1TableViewCell.h"

@implementation TKIMAccountStyle1TableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



+(instancetype)cellWithTableView:(UITableView *)tableView{
    
    TKIMAccountStyle1TableViewCell*  cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([self class])];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([self class])];
//        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.backgroundColor=[UIColor whiteColor];
    }
    return cell;
}

#pragma mark - 初始化方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubViews];
    }
    return self;
}

-(void)addAllSubViews{
    [self.contentView addSubview:self.leftTitle];
    [self.contentView addSubview:self.rightImage];
    [self.contentView  addSubview:self.rightTitle];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    CGFloat margin = 20;
    _leftTitle.frame = CGRectMake(20, 0, width-2*margin, height);
    _rightTitle.frame = CGRectMake(20, 0, width-2*margin, height);
    _rightImage.frame = CGRectMake(width-30-20-20, 7, 30, 30);
}

-(void)setDatamodle:(TKIMAccountModel *)datamodle{
    _datamodle = datamodle;
    
    self.leftTitle.text = _datamodle.lefttitle;
    if (_datamodle.righttitle && _datamodle.righttitle.length) {
        self.rightTitle.text   = _datamodle.righttitle;
        self.rightImage.hidden = YES;
        self.rightTitle.hidden = NO;
    }else{
        
        if (_datamodle.imageDta) {
            self.rightImage.image=(UIImage*)_datamodle.imageDta;
            self.rightTitle.hidden = YES;
            self.rightImage.hidden = NO;
        }else{
            if (_datamodle.rightimagename && _datamodle.rightimagename.length) {
                [self.rightImage sd_setImageWithURL:[[NSURL alloc] initWithString:_datamodle.rightimagename] placeholderImage:[UIImage imageNamed:_datamodle.rightimagename]];
                self.rightTitle.hidden = YES;
                self.rightImage.hidden = NO;
            }
        }

    }

}


#pragma mark--懒加载
-(UILabel*)leftTitle{

    if (_leftTitle == nil) {
        _leftTitle = [[UILabel alloc] init];
        _leftTitle.textAlignment = NSTextAlignmentLeft;
        _leftTitle.backgroundColor = [UIColor clearColor];
    }
    return  _leftTitle;
}

-(UILabel*)rightTitle{

    if (_rightTitle == nil) {
        _rightTitle = [[UILabel alloc] init];
        _rightTitle.textAlignment = NSTextAlignmentRight;
        _rightTitle.backgroundColor = [UIColor clearColor];
    }
    return  _rightTitle;
}

-(UIImageView*)rightImage{

    if (_rightImage == nil) {
        _rightImage = [[UIImageView alloc]init];
        _rightImage.layer.masksToBounds=YES;
        _rightImage.layer.cornerRadius=15;
        _rightImage.backgroundColor=[UIColor redColor];
    }
    return _rightImage;
}

@end
